﻿#region Copyright & License
//
// Project: Quark Framework
// Project site: http://quark.codeplex.com
// See the copyright statement on the project site for more details.
//
// Licensed to the Apache Software Foundation (ASF) under one or more 
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership. 
// The ASF licenses this file to you under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with 
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Quark.Profiler.Framework
{
    #region Event Args

    public class ProfilingTestProjectEventArgs : EventArgs
    {
        private IProfilingContext _context;

        public ProfilingTestProjectEventArgs(IProfilingContext context)
        {
            this._context = context;
        }

        public IProfilingContext Context
        {
            get { return this._context; }
        }
    }

    public class ProfilingTestProjectFinishedEventArgs : ProfilingTestProjectEventArgs
    {
        private bool _isStopped;

        public ProfilingTestProjectFinishedEventArgs(IProfilingContext context, bool isStopped)
            : base(context)
        {
            this._isStopped = isStopped;
        }

        public bool IsStopped
        {
            get { return this._isStopped; }
        }
    }

    public class ProfilingTestCaseEventArgs : EventArgs
    {
        private ProfilingTestProject _project;
        private IProfilingContext _context;

        public ProfilingTestCaseEventArgs(ProfilingTestProject project, IProfilingContext context)
        {
            this._project = project;
            this._context = context;
        }

        public ProfilingTestProject Project
        {
            get { return this._project; }
        }

        public IProfilingContext Context
        {
            get { return this._context; }
        }
    }

    public class ProfilingTestCaseLoopedEventArgs : ProfilingTestCaseEventArgs
    {
        private bool _loopForever;
        private long _loopedTimes;
        private long _maxLoopTimes;

        public ProfilingTestCaseLoopedEventArgs(ProfilingTestProject project, IProfilingContext context, bool loopForever, long loopedTimes, long maxLoopTimes)
            : base(project, context)
        {
            this._loopForever = loopForever;
            this._loopedTimes = loopedTimes;
            this._maxLoopTimes = maxLoopTimes;
        }

        public bool LoopForever
        {
            get { return this._loopForever; }
        }
        public long LoopedTimes
        {
            get { return this._loopedTimes; }
        }
        public long MaxLoopTimes
        {
            get { return this._maxLoopTimes; }
        }
    }

    public class ProfilingTestCaseFinishedEventArgs : ProfilingTestCaseEventArgs
    {
        private bool _isStopped;
        private ProfilingTestCaseCounter[] _counters;

        public ProfilingTestCaseFinishedEventArgs(ProfilingTestProject project, IProfilingContext context, bool isStopped, ProfilingTestCaseCounter[] counters)
            : base(project, context)
        {
            this._isStopped = isStopped;
            this._counters = counters;
        }

        public bool IsStopped
        {
            get { return this._isStopped; }
        }

        public ProfilingTestCaseCounter[] Counters
        {
            get { return this._counters; }
        }
    }

    public class ProfilingTestActivityEventArgs : EventArgs
    {
        private ProfilingTestProject _project;
        private ProfilingTestCase _testCase;
        private IProfilingContext _context;

        public ProfilingTestActivityEventArgs(ProfilingTestProject project, ProfilingTestCase testCase, IProfilingContext context)
        {
            this._project = project;
            this._testCase = testCase;
            this._context = context;
        }

        public ProfilingTestProject Project
        {
            get { return this._project; }
        }

        public ProfilingTestCase TestCase
        {
            get { return this._testCase; }
        }

        public IProfilingContext Context
        {
            get { return this._context; }
        }
    }

    public class ProfilingTestActivityExceptionEventArgs : ProfilingTestActivityEventArgs
    {
        private Exception _exception;

        public ProfilingTestActivityExceptionEventArgs(ProfilingTestProject project, ProfilingTestCase testCase, IProfilingContext context, Exception exception)
            : base(project, testCase, context)
        {
            this._exception = exception;
            this.IgnoreException = false;
        }

        public Exception Exception
        {
            get { return this._exception; }
        }

        public bool IgnoreException { get; set; }
    }

    public class ProfilingTestActivityFinishedEventArgs : ProfilingTestActivityEventArgs
    {
        private bool _isCancelled;
        private bool _isExceptioned;
        private int _executionTicks;

        public ProfilingTestActivityFinishedEventArgs(ProfilingTestProject project, ProfilingTestCase testCase, IProfilingContext context, bool isCancelled, bool isExceptioned, int executionTicks)
            : base(project, testCase, context)
        {
            this._isCancelled = isCancelled;
            this._isExceptioned = isExceptioned;
            this._executionTicks = executionTicks;
        }

        public bool IsCancelled
        {
            get { return this._isCancelled; }
        }

        public bool IsExceptioned
        {
            get { return this._isExceptioned; }
        }

        public int ExecutionTicks
        {
            get { return this._executionTicks; }
        }
    }

    #endregion

    public delegate void ProfilingTestProjectStartingHandler(object sender, ProfilingTestProjectEventArgs e);
    public delegate void ProfilingTestProjectStartedHandler(object sender, ProfilingTestProjectEventArgs e);
    public delegate void ProfilingTestProjectFinishedHandler(object sender, ProfilingTestProjectFinishedEventArgs e);
    public delegate void ProfilingTestProjectStoppingHandler(object sender, ProfilingTestProjectEventArgs e);

    public delegate void ProfilingTestCaseStartingHandler(object sender, ProfilingTestCaseEventArgs e);
    public delegate void ProfilingTestCaseStartedHandler(object sender, ProfilingTestCaseEventArgs e);
    public delegate void ProfilingTestCaseFinishedHandler(object sender, ProfilingTestCaseFinishedEventArgs e);
    public delegate void ProfilingTestCaseStoppingHandler(object sender, ProfilingTestCaseEventArgs e);
    public delegate void ProfilingTestCaseLoopedHandler(object sender, ProfilingTestCaseLoopedEventArgs e);

    public delegate void ProfilingTestActivityExecutingHandler(object sender, ProfilingTestActivityEventArgs e);
    public delegate void ProfilingTestActivityFinishedHandler(object sender, ProfilingTestActivityFinishedEventArgs e);
    public delegate void ProfilingTestActivityExceptionedHandler(object sender, ProfilingTestActivityExceptionEventArgs e);
}
